using MicroMsg.Manager;
using MicroMsg.Resource.@string;
using MicroMsg.Scene;
using MicroMsg.Storage;
using MicroMsg.UI.Page;
using MicroMsg.UI.Util;
using System;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
namespace MicroMsg.UI.UserContrl
{
	public class QQOfflineMsgPluginSetCtrl : PluginSettingBaseCtrl
	{
		private bool mFlagAccountStatusChanged;
		private bool initState;
		internal Grid LayoutRoot;
		internal ClickableLayout btnViewMessages;
		internal ClickableLayout btnSendQQMessages;
		internal MMToggleSwitch toggleReceiveQQOfflineMsg;
		internal ClickableLayout btnClearQQMessages;
		private bool _contentLoaded;
		public QQOfflineMsgPluginSetCtrl()
		{
			this.InitializeComponent();
			base.add_Loaded(new RoutedEventHandler(this.QQOfflineMsgPluginSetCtrl_Loaded));
			base.add_Unloaded(new RoutedEventHandler(this.DoFinish));
		}
		public override void Exit()
		{
			base.Exit();
		}
		public void QQOfflineMsgPluginSetCtrl_Loaded(object sender, RoutedEventArgs e)
		{
			this.InitUI();
		}
		public void DoFinish(object sender, RoutedEventArgs e)
		{
			if (this.mFlagAccountStatusChanged)
			{
				ServiceCenter.sceneNewSync.doScene(1, syncScene.MM_NEWSYNC_SCENE_OTHER);
				this.mFlagAccountStatusChanged = false;
			}
		}
		private void InitUI()
		{
			OnToggleStateChanged onToggleStateChanged = new OnToggleStateChanged(this.checkedStateChanged);
			this.toggleReceiveQQOfflineMsg.onToggleStateChanged = onToggleStateChanged;
			this.toggleReceiveQQOfflineMsg.Text = strings.Plugin_QQOffline_ReceiveMsg;
			Account curAccount = AccountMgr.getCurAccount();
			if (curAccount != null)
			{
				this.toggleReceiveQQOfflineMsg.IsChecked = AccountMgr.RecvOfflineQQMsg;
				this.initState = true;
			}
			if (curAccount.nBindQQ == 0u)
			{
				this.btnClearQQMessages.set_Visibility(1);
				return;
			}
			this.btnClearQQMessages.set_Visibility(0);
		}
		private void btnViewMessages_Click(object sender, RoutedEventArgs e)
		{
			Account curAccount = AccountMgr.getCurAccount();
			if (curAccount.nBindQQ != 0u)
			{
				ToolFunction.GotoPageForUserControl("/Source/Plugin/QQOfflineMsg/UI/QQSessionView.xaml", null, false);
				for (int i = 0; i < PageManager.getInstance().basePageList.get_Count(); i++)
				{
					if (PageManager.getInstance().basePageList.get_Item(i) is QQSessionView)
					{
						PageManager.getInstance().PopPage();
						return;
					}
				}
				return;
			}
			ToolFunction.GotoPageForUserControl("/Source/UI/QQFriends/GoBindQQ.xaml", null, false);
		}
		private void btnSendQQMessages_Click(object sender, RoutedEventArgs e)
		{
			if (!this.toggleReceiveQQOfflineMsg.IsChecked)
			{
				MMMessageBox.Show(strings.Plugin_QQOffline_OffTip, true, "确定");
				return;
			}
			Account curAccount = AccountMgr.getCurAccount();
			if (curAccount.nBindQQ == 0u)
			{
				ToolFunction.GotoPageForUserControl("/Source/UI/QQFriends/GoBindQQ.xaml", null, false);
				return;
			}
			string text = "QQOfflineMsgPulgin";
			ToolFunction.GotoPageForUserControl("/Source/Plugin/Common/QQInfo/UI/ViewQQGroups.xaml", new object[]
			{
				text
			}, false);
		}
		private void checkedStateChanged(object sender, bool isCheckOn)
		{
			if (this.initState && sender == this.toggleReceiveQQOfflineMsg)
			{
				AccountMgr.RecvOfflineQQMsg = isCheckOn;
				this.mFlagAccountStatusChanged = true;
			}
		}
		private void checkedOn(object sender, EventArgs e)
		{
			this.checkedStateChanged(sender, true);
		}
		private void checkedOff(object sender, EventArgs e)
		{
			this.checkedStateChanged(sender, false);
		}
		private void UninstallBtn_Click(object sender, RoutedEventArgs e)
		{
		}
		private void btnClearQQMessages_Click(object sender, RoutedEventArgs e)
		{
			MMMessageBox mMMessageBox = MMMessageBox.Show(strings.Plugin_QQOffline_ClearMsgAlertTitle, strings.Plugin_QQOffline_ClearMsgAlertContent, true, strings.COM_Confirm, strings.COM_Cancel);
			mMMessageBox.ReturnEvent = new DlgReturnEvent(this.OnClearQQMsgHandler);
		}
		private void OnClearQQMsgHandler(DlgReturnEventArg dlgReturnEventArg_0)
		{
			switch (MMMessageBox.GetUserClickResult(dlgReturnEventArg_0))
			{
			case 0:
				QConversationMgr.QQOfflineMsgClearAll();
				break;
			case 1:
				break;
			default:
				return;
			}
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/Plugin/QQOfflineMsg/UI/QQOfflineMsgPluginSetCtrl.xaml", 2));
			this.LayoutRoot = (Grid)base.FindName("LayoutRoot");
			this.btnViewMessages = (ClickableLayout)base.FindName("btnViewMessages");
			this.btnSendQQMessages = (ClickableLayout)base.FindName("btnSendQQMessages");
			this.toggleReceiveQQOfflineMsg = (MMToggleSwitch)base.FindName("toggleReceiveQQOfflineMsg");
			this.btnClearQQMessages = (ClickableLayout)base.FindName("btnClearQQMessages");
		}
	}
}
